package com.three.vip.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.three.core.entity.UserAddress;
import com.three.core.vo.R;
import com.three.vip.service.UserAddressService;
import com.three.vip.vo.UserAddressFormVo;
import com.three.vip.vo.UserAddressSearchFormVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ：JinShiYan
 * @date ：Created in 2025/3/12 18:21
 * @description：
 * @modified By：
 * @version:
 */
@RestController
@RequestMapping("/vip/userAddress")
public class UserAddressController {

    @Autowired
    private UserAddressService userAddressService;

    @PostMapping("/AddressManagement")
    public R<IPage<UserAddress>> AddressManagement(@RequestBody UserAddressSearchFormVo userAddressSearchFormVo) {
        return userAddressService.selectByCondition(userAddressSearchFormVo);
    }

    @PostMapping("/updateAddress")
    public R<String> updateAddress(@RequestBody UserAddressFormVo userAddressFormVo) {
        return userAddressService.updateAddress(userAddressFormVo);
    }
    //通过addressId查询地址,修改地址信息回显数据
    @GetMapping("/selectOneAddress")
    public R<UserAddress> selectOneAddress(Integer addressId) {
        return userAddressService.selectOneAddress(addressId);
    }
    //添加地址
    @PostMapping("/addAddress")
    public R<UserAddress> addAddress(@RequestBody UserAddress userAddress) {
        return userAddressService.addAddress(userAddress);
    }
    //更新地址
    @PostMapping("/updateUserAddress")
    public R<UserAddress> updateUserAddress(@RequestBody UserAddress userAddress) {
        return userAddressService.updateUserAddress(userAddress);
    }
    //删除地址
    @DeleteMapping("/deleteUserAddress")
    public R<String> deleteUserAddress(Integer addressId) {
        return userAddressService.deleteUserAddress(addressId);
    }
    //查询当前用户保存的所有地址信息
    @GetMapping("/selectAddressById")
    public R<List<UserAddress>> selectAddressById(Integer userId) {
        return userAddressService.selectAddressById(userId);
    }

}
